﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Core.Dao;
using Core.Entity;
using System.Data;

namespace Core.Business
{
    public class OrderLineBus
    {
        private OrderLineDao dao;
        public OrderLineBus()
        {
            dao = new OrderLineDao();
        }

        public bool insert(OrderLine orderLine) {
            return dao.insert(orderLine);
        }

        public bool update(OrderLine orderLine) {
            return dao.update(orderLine);
        }

        public bool delete(int id) {
            return dao.delete(id);
        }

        public bool delete(String ids) {
            return dao.delete(ids);
        }

        public OrderLine get(int id) {
            DataTable dt = dao.get(id);
            OrderLine orderLine = new OrderLine();

            if (dt.Rows.Count > 0)
            {
                orderLine.Id = Convert.ToInt32(dt.Rows[0]["OLN_ID"]);
                orderLine.OrderId = Convert.ToInt32(dt.Rows[0]["ORD_ID"]);
                orderLine.ServiceId = Convert.ToInt32(dt.Rows[0]["SVC_ID"]);
                orderLine.Quantity = Convert.ToInt32(dt.Rows[0]["OLN_QUANTITY"]);
                orderLine.Price = Convert.ToDouble(dt.Rows[0]["OLN_PRICE"]);
                orderLine.Desc = dt.Rows[0]["OLN_DESC"].ToString();
            }
            return orderLine;
        }

        public List<OrderLine> getAll() {
            DataTable dt = dao.getAll();
            List<OrderLine> list = new List<OrderLine>();

            if (dt.Rows.Count > 0)
            {
                foreach (DataRow dr in dt.Rows)
                {
                    OrderLine orderLine = new OrderLine();
                    orderLine.Id = Convert.ToInt32(dr["OLN_ID"]);
                    orderLine.OrderId = Convert.ToInt32(dr["ORD_ID"]);
                    orderLine.ServiceId = Convert.ToInt32(dr["SVC_ID"]);
                    orderLine.Quantity = Convert.ToInt32(dr["OLN_QUANTITY"]);
                    orderLine.Price = Convert.ToDouble(dr["OLN_PRICE"]);
                    orderLine.Desc = dr["OLN_DESC"].ToString();

                    list.Add(orderLine);
                }

            }
            return list;
        }
    }
}
